<template>
  <view class="drvier-list">
    <template v-for="item in list" :key="item.ID">
      <wd-card :title="'司机姓名：' + item.COL_0">
        <view class="flex justify-between items-center" @click="goEdit(item)">
          <view>
            <view class="flex justify-between">
              <view>项目：</view>
              {{ item.COL_3 }}
            </view>
            <view class="flex justify-between" @click.stop="openPhone(item)">
              <view>电话：</view>
              {{ item.COL_1 }} 点击拨打
            </view>
          </view>
          <view>
            <wd-button size="small" type="success">编辑</wd-button>
          </view>
        </view>
      </wd-card>
    </template>
    <view class="add w-full">
      <wd-button type="success" block @click="goAdd">添加司机</wd-button>
    </view>
  </view>
</template>
<script setup>
import {onShow} from "@dcloudio/uni-app";

const {userInfo} = storeToRefs(useAuthStore()) // 解构pinia的store
const list = ref([])
onShow(() => {
  getList()
})
const getList = () => {
  uni.request({
    url: 'https://miniapp.zhangmushiye.com/bi-api/report/dataapi/drivers',
    method: 'GET',
    data: {
      name: userInfo.value.name
    },
    success: (res) => {
      list.value = res.data.data
    }
  })
}

const goAdd = () => {
  uni.navigateTo({
    url: '/pages/publish/driver'
  })
}

const openPhone = (item) => {
  uni.makePhoneCall({
    phoneNumber: item.COL_1
  })
}

const goEdit = (item) => {
  uni.navigateTo({
    url: '/pages/publish/driver?item=' + encodeURIComponent(JSON.stringify(item))
  })
}
</script>

<style scoped lang="scss">
.drvier-list{
  position: relative;
  .add{
    position: fixed;
    // 安全区域
    bottom: var(--safe-area-inset-bottom);
  }
}
</style>